package com.eCommerce.server.svco.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Transactional;


import com.eCommerce.corecontract.criteria.CommandeCriteria;
import com.eCommerce.corecontract.dto.ClientDTO;
import com.eCommerce.corecontract.dto.CommandeDTO;
import com.eCommerce.corecontract.dto.UserDTO;
import com.eCommerce.corecontract.exception.EcommerceException;
import com.eCommerce.corecontract.exception.EcommerceSISVException;
import com.eCommerce.corecontract.exception.EcommerceSVCOException;

import com.eCommerce.server.corebackend.sisv.ICommandeSISV;
import com.eCommerce.server.corebackend.sisv.SISVFinder;
import com.eCommerce.server.corebackend.util.BackEndConstants;
import com.eCommercecorecontract.svco.ICommandeSVCO;
@Transactional
public class CommandeSVCOImpl extends AbstractCommonSVCO implements ICommandeSVCO, Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static Logger log =Logger.getLogger(CommandeSVCOImpl.class);
	private SISVFinder sisvFinder = null;

	private ICommandeSISV _commandeSISV=null;
	public CommandeSVCOImpl(SISVFinder sisvFinder) throws Exception{
		this.sisvFinder = sisvFinder;
		_commandeSISV = (ICommandeSISV) sisvFinder.get(BackEndConstants.SISV_COMMANDE );
		/* if (!TransactionSynchronizationManager.isSynchronizationActive())
			   TransactionSynchronizationManager.initSynchronization();
*/
	
		
	}

	public Long enregistrerCommande(CommandeDTO commandeDTO)
			throws EcommerceException {
		
		try {
			
			return _commandeSISV.enregistrerCommande(commandeDTO);
		} catch (EcommerceException e) {
			// TODO Auto-generated catch block
			throw e;
		}
		catch(Exception ex)
		{
			Object[] arg1 = new Object[1];

			EcommerceSVCOException svcoException = new EcommerceSVCOException(messagesXmlFileName, "ECOMMERCESVCOCOMMANDE-001", arg1, ex.getMessage());
			log.error(svcoException.getMessage());
			throw svcoException;
		}
		
	}

	public List listerCommandes() throws EcommerceException {
		// TODO Auto-generated method stub
		try {
			return _commandeSISV.listerCommande();//.enregistrerCommande(commandeDTO);
		} catch (EcommerceException e) {
			// TODO Auto-generated catch block
			throw e;
		}
		catch(Exception ex)
		{
			Object[] arg1 = new Object[1];

			EcommerceSVCOException svcoException = new EcommerceSVCOException(messagesXmlFileName, "ECOMMERCESVCOCOMMANDE-004", arg1, ex.getMessage());
			log.error(svcoException.getMessage());
			throw svcoException;
		}
	}

	public List rechercherCommandes(
			CommandeCriteria commandeCriteria) throws EcommerceException {
		// TODO Auto-generated method stub
		try {
			return _commandeSISV.rechercherCommande(commandeCriteria);//listerCommande();//.enregistrerCommande(commandeDTO);
		} catch (EcommerceException e) {
			// TODO Auto-generated catch block
			throw e;
		}
		catch(Exception ex)
		{
			Object[] arg1 = new Object[1];

			EcommerceSVCOException svcoException = new EcommerceSVCOException(messagesXmlFileName, "ECOMMERCESVCOCOMMANDE-004", arg1, ex.getMessage());
			log.error(svcoException.getMessage());
			throw svcoException;
		}
	}

	public CommandeDTO visualiserCommande(CommandeDTO commandeDTO)
			throws EcommerceException {
		// TODO Auto-generated method stub
		try {
			return _commandeSISV.visualiserCommande(commandeDTO);//)listerCommande();//.enregistrerCommande(commandeDTO);
		} catch (EcommerceException e) {
			// TODO Auto-generated catch block
			throw e;
		}
		catch(Exception ex)
		{
			Object[] arg1 = new Object[1];

			EcommerceSVCOException svcoException = new EcommerceSVCOException(messagesXmlFileName, "ECOMMERCESVCOCOMMANDE-003", arg1, ex.getMessage());
			log.error(svcoException.getMessage());
			throw svcoException;
		}
	}

	public List rechercherCommandeDuClient(UserDTO clientDTO)
			throws EcommerceException {
		// TODO Auto-generated method stub
		try {
			return _commandeSISV.rechercherCommandeDuClient(clientDTO);//rechercherCommande(commandeCriteria);//listerCommande();//.enregistrerCommande(commandeDTO);
		} catch (EcommerceException e) {
			// TODO Auto-generated catch block
			throw e;
		}
		catch(Exception ex)
		{
			Object[] arg1 = new Object[1];

			EcommerceSVCOException svcoException = new EcommerceSVCOException(messagesXmlFileName, "ECOMMERCESVCOCOMMANDE-007", arg1, ex.getMessage());
			log.error(svcoException.getMessage());
			throw svcoException;
		}
	}

}
